<?php
/**
 * Object Relational Persistence Mapping Class for table: pay_receipt_item
 *
 * @package	com.athena
 * @author	LHV
 */
class PayReceiptItem extends ORDataObject {

	/**#@+
	 * Fields of table: pay_receipt_item mapped to class members
	 */
	var $pay_receipt_item_id   = '';
	var $pay_receipt_id        = '';
	var $service_id            = '';
	var $service_name          = '';
	var $quantity              = '';
	var $amount                = '';
	var $doctor_id		       = '';
	var $pay_payment_item_id   = '';
	var $enum_item_type        = '';
	var $deleted               = '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'pay_receipt_item';

	/**
	 * Primary Key
	 */
	var $_key = 'pay_receipt_item_id';

	/**
	 * Internal Name
	 */
	var $_internalName = 'PayReceiptItem';

	/**
	 * Handle instantiation
	 */
	function PayReceiptItem() {
		parent::ORDataObject();
	}

	public function setData($receiptId, $paymentItemId, $itemType, $serviceId, $serviceName,
	       $quantity, $amount, $doctorId) {
        $data   =   array(
		    'pay_receipt_id'        =>   $receiptId,
            'pay_payment_item_id'   =>   $paymentItemId,
            'enum_item_type'        =>   $itemType,
            'service_id'            =>   $serviceId,
            'service_name'          =>   $serviceName,
            'quantity'              =>   $quantity,
            'amount'                =>   $amount,
            'doctor_id'             =>   $doctorId
        );
        $this->populateArray($data);
	}

	public function getReceiptItems($receiptId) {
		$sql	=	array(
			'cols'	=>	"*",
			'from'	=>	"$this->_table",
			'where'	=>	"pay_receipt_id = '$receiptId'"
		);
		$ds	=	new Datasource_sql();
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}

	public function getItemsByPaymentItem($paymentItemId) {
        $sql    =   array(
            'cols'  =>  "pay_receipt_item_id, pay_receipt_id, service_id, service_name, " .
            		" enum_item_type, quantity, amount, doctor_id",
            'from'  =>  "$this->_table",
            'where' =>  "pay_payment_item_id = '$paymentItemId'"
        );
        $ds =   new Datasource_sql();
        $ds->setup($this->_db, $sql);
        return $ds->toArray();
	}

	public function updateStatus($itemId, $status) {
        $sql    =   "UPDATE $this->_table SET deleted = $status WHERE $this->_key = '$itemId'";
        $res   =   $this->_execute($sql);
        return $res;
	}
}
?>
